﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace LOGIN
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
             
        }
     
       
       public static Boolean MedicineManager = true;
       public static Boolean GiveOutMedicine = true;
       public static Boolean OrdersManager = true;
       public static Boolean SupplierManager = true;
       public static Boolean UserCenter = true;
       public static Boolean UserManager = true;
       
       private void 填写订单表ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           Orders f = new Orders();
           f.Show();
       }

       private void 采购计划单ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           cancel f = new cancel();
           f.Show();
       }

       private void 入库编制ToolStripMenuItem_Click(object sender, EventArgs e)
       {
           Input Input = new Input();
           Input.Show();
       }

       private void 月底结算ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           MonthlyendingReports f = new MonthlyendingReports();
           f.Show();
       }

       private void 月底盘存ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           InventoryProcessing f = new InventoryProcessing();
           f.Show();
       }

       private void 库存调整ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           Replenishment r = new Replenishment();
           r.Show();
       }

       private void 调价管理ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           PriceChange f = new PriceChange();
           f.Show();
       }

       private void 药房领药ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
            UseTable f = new UseTable();
            f.Show();
        
       }

       private void 出库处理ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           OutputTable f = new OutputTable();
           f.Show();
       }

       private void 代码字典ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           Code f = new Code();
           f.Show();
       }

       private void Main_Load(object sender, EventArgs e)
       {
           toolStripStatusLabel1.Text = "操作者：" + ordersHelper.UserName+"      ";
           toolStripStatusLabel4.Text = "当前时间：" + DateTime.Now.ToLongDateString() + "        ";
           toolStripStatusLabel5.Text = "版权所有  福建中医药大学2016级信管李堞";
           

           skinEngine1.SkinFile = Application.StartupPath + @"\RealOne.ssk";
          
           SqlConnection sqlConnection = new SqlConnection();
           sqlConnection.ConnectionString =
               "Server=(local);Database=MyHospital;Integrated Security=sspi";
           SqlCommand sqlCommand = new SqlCommand();
           sqlCommand.Connection = sqlConnection;
           sqlCommand.CommandText = "SELECT RoleName,GiveOutMedicine,MedicineManager,OrdersManager,SupplierManager,UserCenter,UserManager FROM managerRole Where RoleID=@RoleID;";
           sqlCommand.Parameters.AddWithValue("@RoleID", ordersHelper.RoleID);
           
           sqlConnection.Open();
           SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
           int

                nameOrdinal = sqlDataReader.GetOrdinal("GiveOutMedicine")
               , genderOrdinal = sqlDataReader.GetOrdinal("MedicineManager")
               , birthDateOrdinal = sqlDataReader.GetOrdinal("OrdersManager")
               , classOrdinal = sqlDataReader.GetOrdinal("SupplierManager")
               , specialityOrdinal = sqlDataReader.GetOrdinal("UserCenter")
                , UserManagerOrdianl = sqlDataReader.GetOrdinal("UserManager");
           if (sqlDataReader.Read())
           {
               
               GiveOutMedicine = sqlDataReader.GetBoolean(nameOrdinal);
               MedicineManager = sqlDataReader.GetBoolean(genderOrdinal);
               OrdersManager = sqlDataReader.GetBoolean(birthDateOrdinal);
               SupplierManager = sqlDataReader.GetBoolean(classOrdinal);
               UserCenter = sqlDataReader.GetBoolean(specialityOrdinal);
               UserManager = sqlDataReader.GetBoolean(UserManagerOrdianl);

               //this.txb_Speciality.Text =                                                                  //学生特长可为空值，而强类型Get方法无法读取数据库空值，需借助方法IsDBNull判断并处理空值；
               //    sqlDataReader.IsDBNull(specialityOrdinal) ? null : sqlDataReader.GetString(specialityOrdinal);
           }
           sqlDataReader.Close();
           if (Main.OrdersManager == false)
           {
               入库管理ToolStripMenuItem.Enabled=false;
           }
           if (Main.GiveOutMedicine == false)
           {
               出库管理ToolStripMenuItem.Enabled=false;
           }
           if (Main.MedicineManager == false)
           {
               在库管理ToolStripMenuItem.Enabled=false;
           }
           if (Main.SupplierManager == false)
           {
               公司汇总ToolStripMenuItem1.Enabled = false;
           }
           if (Main.UserCenter == false)
           {
               代码字典ToolStripMenuItem1.Enabled = false;
           }
           if (Main.UserManager == false)
           {
               权限管理ToolStripMenuItem1.Enabled = false;
           }

           
       }

       private void 药品购进汇总报表ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           InputtotalTable f = new InputtotalTable();
           f.Show();
       }

       private void 公司汇总ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           CompanyTable f = new CompanyTable();
           f.Show();
       }

       private void 权限管理ToolStripMenuItem1_Click(object sender, EventArgs e)
       {
           ManagerRole f =new ManagerRole();
           f.Show();
       }

       private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
       {
           Application.Exit();
       }

       private void 使用说明ToolStripMenuItem_Click(object sender, EventArgs e)
       {
           HelpText f = new HelpText();
           f.Show();
       }





      
        
        //private void 出库ToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    Output Output = new Output();
        //    Output.Show();
        //}

       

   

       

       

       
       
       

       
        

       
        

       

        
        
        
       

        

        

       
        

        

       

       

      
        
        
        
     
     

       

        
    }
}
